{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7acb034c",
   "metadata": {},
   "source": [
    "* 20210-10-18\n",
    "* 课程：Python语言\n",
    "* week05"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c545fa34",
   "metadata": {},
   "source": [
    "# 1.用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c41781d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：Jaehyun\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Jaehyun'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"请输入你的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "12c920bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：Jaehyun\n",
      "请输入你的密码：031204\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入你的账号\")\n",
    "password = input(\"请输入你的密码\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97627988",
   "metadata": {},
   "source": [
    "* 笔记：等号代表赋值，把右边的内容存放到左边的内容当中。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d612242d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jaehyun\n",
      "031204\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "fcf0b17e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号Jaehyun\n",
      "请输入你的密码031204\n",
      "Who's there?The BND!!\n"
     ]
    }
   ],
   "source": [
    "# 假设 正确的账号：Jaehyun\n",
    "# 假设 正确的密码：031204\n",
    "\n",
    "# 登录系统\n",
    "username = input(\"请输入你的账号\")\n",
    "password = input(\"请输入你的密码\")\n",
    "# 两种登录可能，1.登录成功，2.登录失败\n",
    "if username == \"Jaehyun\" and password == \"031204\":\n",
    "    # 情景1.账户和密码都正确，则登录成功\n",
    "    print(\"Who's there?The BND!!\")\n",
    "else:\n",
    "    # 情景2.账户或者密码存在不正确的数据\n",
    "    print(\"你输入的账户或者密码错误\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9ff8824",
   "metadata": {},
   "source": [
    "* 笔记：\n",
    "> 1. == 代表判断左右两边是否相等，即\"等于\"\n",
    "> 2. 所有的符号要用英文的符号，例如冒号:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8261a521",
   "metadata": {},
   "source": [
    "# 2.用户输出（格式化）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c3bf5e2",
   "metadata": {},
   "source": [
    "## 2.1 注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5c382299",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一种：# 表示单行注释，如上述用户输入的学习中，每一行进行文字描述的注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "33a086b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "111\n"
     ]
    }
   ],
   "source": [
    "# 第二种：\"\"\"注释内容\"\"\"  多行注释，用于记录学习之前写过的程序，不会被执行\n",
    "\"\"\"\n",
    "\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait-time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)\n",
    "\"\"\"\n",
    "print(\"111\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "929071f5",
   "metadata": {},
   "source": [
    "# 2.2 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d64556d4",
   "metadata": {},
   "source": [
    "2.2.1 字符串的拼接实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a42b8e99",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的姓名：YangONE\n",
      "请输入你的年龄：20\n",
      "请输入你的职业：Student\n",
      "请输入你的薪水：60'000\n"
     ]
    }
   ],
   "source": [
    "# 指定格式的简历\n",
    "\n",
    "# 用户输入信息\n",
    "name = input(\"请输入你的姓名：\")\n",
    "age = input(\"请输入你的年龄：\")\n",
    "job = input(\"请输入你的职业：\")\n",
    "salary = input(\"请输入你的薪水：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5eafb16a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------- INFOYangONE--------\n",
      "姓名：YangONE\n",
      "年龄：20\n",
      "工作：Student\n",
      "薪水：60'000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输入内容\n",
    "\n",
    "INFO = \"\"\"-------- INFO\"\"\" + name + \"\"\"--------\n",
    "姓名：\"\"\" + name + \"\"\"\n",
    "年龄：\"\"\" + age + \"\"\"\n",
    "工作：\"\"\" + job + \"\"\"\n",
    "薪水：\"\"\" + salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7668dc4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "* 笔记：上述代码使用的方法是“字符串的拼接”，用+实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b71a0f36",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------- INFO name --------\n",
      "姓名：YangONE\n",
      "年龄：20\n",
      "工作：Student\n",
      "薪水：60'000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输入内容(错误示范)\n",
    "\n",
    "INFO = \"\"\"-------- INFO name --------\n",
    "姓名：\"\"\" + name + \"\"\"\n",
    "年龄：\"\"\" + age + \"\"\"\n",
    "工作：\"\"\" + job + \"\"\"\n",
    "薪水：\"\"\" + salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fde061f",
   "metadata": {},
   "source": [
    "## 2.2.2占位符实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cdbbbe25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------- INFO YangONE --------\n",
      "姓名：YangONE\n",
      "年龄：20\n",
      "工作：Student\n",
      "薪水：60'000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\"-------- INFO %s --------\n",
    "姓名：%s\n",
    "年龄：%s\n",
    "工作：%s\n",
    "薪水：%s\"\"\"%(name,name,age,job,salary)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9325036b",
   "metadata": {},
   "source": [
    "* 笔记：占位符比较适用于格式化字段较少的文本处理\n",
    "> 1.%s 占位符是字符串\n",
    "> 2.%d 占位符是数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf42c736",
   "metadata": {},
   "source": [
    "## 2.2.3格式化方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3f5f1db0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------- INFO YangONE --------\n",
      "姓名：YangONE\n",
      "年龄：20\n",
      "工作：Student\n",
      "薪水：60'000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "# N:姓名, A:年龄,J:工作,S:薪水\n",
    "INFO = \"\"\"-------- INFO {N} --------\n",
    "姓名：{N}\n",
    "年龄：{A}\n",
    "工作：{J}\n",
    "薪水：{S}\"\"\".format(N = name,J = job, S = salary, A = age)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be2b83fd",
   "metadata": {},
   "source": [
    "* 笔记：format方法可以解决占位符的两个痛点：\n",
    "> 1.不再考量位置顺序\n",
    "> 2.解决重复字段出现的问题，只需要赋值一次，如上述：N=name，只需要写一次即可"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "765e6312",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute\n",
      "Not an odd minute\n",
      "This minute seems a little odd.\n",
      "This minute seems a little odd.\n",
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_minute = datetime.today().second\n",
    "    if right_this_minute in odds:\n",
    "        print(\"This minute seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd minute\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time)#时间静止wait_time的时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7080de30",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
